package testGroovy

def list = [0, 1, 2, null]
def list1 = [0, 1, 2, 3, 4]
println list
list -= null
println list
list = list1
println list


import java.text.SimpleDateFormat
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatterBuilder

import static java.time.LocalDate.now as today

println today()

def list3 = [3, 4, 5]
def greaterThanTwo = list3.every { it > 2 }

println greaterThanTwo

def _DATETIME_FORMAT3 = new DateTimeFormatterBuilder().appendPattern('yyyy-MM-dd').toFormatter()
println LocalDate.parse('2015-09-12').plusDays(1).format(_DATETIME_FORMAT3)
def velist1 = [[
                   "_id"             : "5166f9e9577b6735474c2e9f",
                   "brand_id"        : "402880ef0ca9c2b6010cc27929a6002c",
                   "brand_name"      : "上海通用别克",
                   "engine_desc"     : "2.0L",
                   "family_name"     : "君威",
                   "gearbox_name"    : "手自一体",
                   "import_flag"     : 1,
                   "market_date"     : 201003,
                   "parent_id"       : "4028808827d1db190127db14b7b70744",
                   "parent_veh_code" : "BKAAMD0022",
                   "parent_veh_name" : "2010款 世博版",
                   "price"           : 183900,
                   "seat"            : 5,
                   "seat_flag"       : 0,
                   "standard_name"   : "别克SGM7205ATA轿车",
                   "taxprice"        : 199600,
                   "vehicle_fgw_code": "SGM7205ATA",
                   "vehicle_id"      : "4028808827ad1bbd0127bcb0a5790c09",
                   "vin_code"        : "LSGGA54Y#########LSGGA53Y#########"
               ]]

def velist = [[
                  "_id"             : "5166f9e9577b6735474c2e9f",
                  "brand_id"        : "402880ef0ca9c2b6010cc27929a6002c",
                  "brand_name"      : "上海通用别克",
                  "engine_desc"     : "2.0L",
                  "family_name"     : "君威",
                  "gearbox_name"    : "手自一体",
                  "import_flag"     : 1,
                  "market_date"     : 201003,
                  "parent_id"       : "4028808827d1db190127db14b7b70744",
                  "parent_veh_code" : "BKAAMD0022",
                  "parent_veh_name" : "2010款 世博版",
                  "price"           : 183900,
                  "seat"            : 5,
                  "seat_flag"       : 0,
                  "standard_name"   : "别克SGM7205ATA轿车",
                  "taxprice"        : 199600,
                  "vehicle_fgw_code": "SGM7205ATA",
                  "vehicle_id"      : "4028808827ad1bbd0127bcb0a5790c09",
                  "vin_code"        : "LSGGA54Y#########LSGGA53Y#########"
              ], [
                  "_id"             : "5166f9e9577b6735474c3a1a",
                  "brand_id"        : "402880ef0ca9c2b6010cc27929a6002c",
                  "brand_name"      : "上海通用别克",
                  "engine_desc"     : "2.0L",
                  "family_name"     : "君威",
                  "gearbox_name"    : "手自一体",
                  "import_flag"     : 1,
                  "market_date"     : 201101,
                  "parent_id"       : "402880883285071a01328ae201c005f1",
                  "parent_veh_code" : "BKAAMD0031",
                  "parent_veh_name" : "2011款 舒适版",
                  "price"           : 164900,
                  "seat"            : 5,
                  "seat_flag"       : 0,
                  "standard_name"   : "别克SGM7205ATA轿车",
                  "taxprice"        : 179000,
                  "vehicle_fgw_code": "SGM7205ATA",
                  "vehicle_id"      : "402880882f2a43c3012f527284bc17c2",
                  "vin_code"        : "LSGGA54Y#########LSGGA53Y#########"
              ], [
                  "_id"             : "5166f9ea577b6735474c641b",
                  "brand_id"        : "402880ef0ca9c2b6010cc27929a6002c",
                  "brand_name"      : "上海通用别克",
                  "engine_desc"     : "2.0L",
                  "family_name"     : "君威",
                  "gearbox_name"    : "手自一体",
                  "import_flag"     : 1,
                  "market_date"     : 200812,
                  "parent_id"       : "90162f76c057ffc800000000e30f532c",
                  "parent_veh_code" : "BKAAMD0015",
                  "parent_veh_name" : "2009款 GL精英版",
                  "price"           : 196900,
                  "seat"            : 5,
                  "seat_flag"       : 0,
                  "standard_name"   : "别克SGM7205ATA轿车",
                  "taxprice"        : 213700,
                  "vehicle_fgw_code": "SGM7205ATA",
                  "vehicle_id"      : "402880881ddc5b6e011df58711d30355",
                  "vin_code"        : "LSGGA54Y#########LSGGA53Y#########"
              ], [
                  "_id"             : "5166f9ea577b6735474c641d",
                  "brand_id"        : "402880ef0ca9c2b6010cc27929a6002c",
                  "brand_name"      : "上海通用别克",
                  "engine_desc"     : "2.0L",
                  "family_name"     : "君威",
                  "gearbox_name"    : "手自一体",
                  "import_flag"     : 1,
                  "market_date"     : 200812,
                  "parent_id"       : "90162f85c057ffc8000000006f03a992",
                  "parent_veh_code" : "BKAAMD0014",
                  "parent_veh_name" : "2009款 G舒适版",
                  "price"           : 176900,
                  "seat"            : 5,
                  "seat_flag"       : 0,
                  "standard_name"   : "别克SGM7205ATA轿车",
                  "taxprice"        : 192000,
                  "vehicle_fgw_code": "SGM7205ATA",
                  "vehicle_id"      : "402880881ddc5b6e011df583e7b4034d",
                  "vin_code"        : "LSGGA54Y#########LSGGA53Y#########"
              ]]
def options = velist.collect { vehicle ->
    [
        [
            vehicleId  : vehicle.vehicle_id,
            vehicleName: "${vehicle.standard_name} ${vehicle.parent_veh_name} ${vehicle.seat_flag != '1' ? vehicle.seat + '座' : ''} (参考价)${0 == 1 && !vehicle.supervise ? vehicle.taxprice : vehicle.taxprice}"
        ]
    ]
}.inject { prev, curr ->
    prev + curr
}

//println options

println getCarModel(velist1, '402880881ddc5b6e011df583e7b4034d')

def getCarModel(vehicles, vehicleId) {
    if (vehicles.size() > 1) {
        def vehicle = vehicles.find { item ->
            item.vehicle_id == vehicleId
        }
        vehicle ? vehicle : vehicles[0]
    } else {
        vehicles[0]
    }
}

def supps = [
    [path: 'supplementInfo.autoModel'],
    [path: 'supplementInfo.autoMode']
]

def map = [
    'auto.enrollDate'         : true,
    'auto.autoType.code'      : true,
    'supplementInfo.autoModel': true
]
def condition = map.findResults { k, v ->
    supps.find { supp ->
        supp.path == k && v
    }
}

println condition

println map?.b?.c
println '========='
def testClosure = { arg1, arg2 = { it }, arg3 ->
    println arg1
    println arg2
    println arg3
}

testClosure.curry(1, null).call(3)
println '========='
testClosure.curry(1).call(3, 2)
println '========='
testClosure.curry(1, 43, 2).call()
println '========='
//testClosure.curry(1).call(1,3,2)

def glassRelationItems = ['a', 'b']
def (glass, glassType) = glassRelationItems
println "$glass $glassType"

def combinedItems = [false, true, false]
def var = println(combinedItems.any { combinedItem ->
    combinedItem
})
var

def datae = '2012/12/12'
println datae.replace('/', '-')


def vehicle = [
    "_id"             : "5267a52b8d4d78ce24000010",
    "brand_id"        : "I0000000000000000200000000000309",
//    "brand_name"      : "路虎",
    "engine_desc"     : "3.0T",
//    "family_name"     : "揽胜",
    "gearbox_name"    : "手自一体",
    "import_flag"     : 2,
    "market_date"     : 201306,
    "parent_id"       : "4028b28841cafa3d0141e3f1de640d14",
    "parent_veh_code" : "LHBAEI0056",
    "parent_veh_name" : "2014款 Vogue汽油",
    "price"           : 1408000,
    "seat"            : 5,
    "seat_flag"       : 0,
//    "standard_name"   : "揽胜RANGE ROVER 3.0T越野车",
    "taxprice"        : 1528300,
    "ton_number"      : "",
    "vehicle_fgw_code": "RANGE ROVER 3.0T",
    "vehicle_id"      : "4028b2883f506d56013fc6810f780838",
    "vehicle_type"    : "A012",
    "vin_code"        : "SALGA2VF#########",
    "whole_weight"    : ""
]

println vehicle.collect { key, value ->
    key == 'brand_name' || key == 'family_name' || key == 'standard_name' ? value : null
} - null

def quotingTestData = [[1,'2'],[2,'2'],[3,'2'],[4,'3']]
def ids = [1,2]

println quotingTestData.findResults { item ->
    ids.findResult { id ->
        id == item[0] ? item : null
    }
}